/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pt.iasd.youthshelter.wizards.core.events.graduation;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.ResourceBundle;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.jdesktop.swingx.JXDatePicker;
import pt.iasd.youthshelter.wizards.core.WizardKeys;

public final class GraduationSchoolVisualPanel1 extends JPanel implements DocumentListener, ActionListener {
    private static final ResourceBundle bundle = java.util.ResourceBundle.getBundle("pt/iasd/youthshelter/wizards/core/Bundle");
    /**
     * Creates new form GraduationSchoolVisualPanel1
     */
    public GraduationSchoolVisualPanel1() {
        this(null, null, null);
    }
    
    /**
     * Creates new form GraduationSchoolVisualPanel1
     */
    public GraduationSchoolVisualPanel1(String name, Date start, Date end) {
        initComponents();
        boolean editionMode = false;
        if(name != null && !name.isEmpty()) {
            this.NameTextField.setText(name);
            editionMode = true;
        }
        if(start != null) {
            this.StartDatePicker.setDate(start);
            editionMode = true;
        }
        if(end != null) {
            this.EndDatePicker.setDate(end);
            editionMode = true;
        }
        if(editionMode) {
            firePropertyChange(WizardKeys.PROP_ANY, 0, 1);
        }
    }

    @Override
    public String getName() {
        return WizardKeys.PROP_GSCHOOL_STEPS[0];
    }

    public JXDatePicker getEndDatePicker() {
        return EndDatePicker;
    }

    public JTextField getNameTextField() {
        return NameTextField;
    }

    public JXDatePicker getStartDatePicker() {
        return StartDatePicker;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        NameLabel = new javax.swing.JLabel();
        NameTextField = new javax.swing.JTextField();
        GradSchoolSeparator = new javax.swing.JSeparator();
        StartDateLabel = new javax.swing.JLabel();
        EndDateLabel = new javax.swing.JLabel();
        StartDatePicker = new org.jdesktop.swingx.JXDatePicker();
        EndDatePicker = new org.jdesktop.swingx.JXDatePicker();

        org.openide.awt.Mnemonics.setLocalizedText(NameLabel, bundle.getString("GraduationSchoolVisualPanel1.NameLabel.text"));

        NameTextField.setPreferredSize(new java.awt.Dimension(300, 20));
        NameTextField.getDocument().addDocumentListener(this);

        org.openide.awt.Mnemonics.setLocalizedText(StartDateLabel, bundle.getString("GraduationSchoolVisualPanel1.StartDateLabel.text"));

        org.openide.awt.Mnemonics.setLocalizedText(EndDateLabel, bundle.getString("GraduationSchoolVisualPanel1.EndDateLabel.text"));

        StartDatePicker.setDate(new Date());
        StartDatePicker.setMaximumSize(new java.awt.Dimension(150, 22));
        StartDatePicker.setMinimumSize(new java.awt.Dimension(150, 22));
        StartDatePicker.setPreferredSize(new java.awt.Dimension(150, 22));
        StartDatePicker.addActionListener(this);

        EndDatePicker.setDate(new Date());
        EndDatePicker.setMaximumSize(new java.awt.Dimension(150, 22));
        EndDatePicker.setMinimumSize(new java.awt.Dimension(150, 22));
        EndDatePicker.setPreferredSize(new java.awt.Dimension(150, 22));
        EndDatePicker.addActionListener(this);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(NameLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(NameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(EndDateLabel)
                            .addComponent(StartDateLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(StartDatePicker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(EndDatePicker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(GradSchoolSeparator)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(NameLabel)
                    .addComponent(NameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(GradSchoolSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(StartDateLabel)
                    .addComponent(StartDatePicker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(EndDateLabel)
                    .addComponent(EndDatePicker, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel EndDateLabel;
    private org.jdesktop.swingx.JXDatePicker EndDatePicker;
    private javax.swing.JSeparator GradSchoolSeparator;
    private javax.swing.JLabel NameLabel;
    private javax.swing.JTextField NameTextField;
    private javax.swing.JLabel StartDateLabel;
    private org.jdesktop.swingx.JXDatePicker StartDatePicker;
    // End of variables declaration//GEN-END:variables

    @Override
    public void insertUpdate(DocumentEvent e) {
        changedUpdate(e);
    }

    @Override
    public void removeUpdate(DocumentEvent e) {
        changedUpdate(e);
    }

    @Override
    public void changedUpdate(DocumentEvent e) {
        firePropertyChange(WizardKeys.PROP_ANY, 0, 1);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        firePropertyChange(WizardKeys.PROP_ANY, 0, 1);
    }
}
